<template>
  <div class="app-container">
    <!-- 条件栏 -->
    <div v-show="!modifyInfo.visible">
      <div class="filter-wrapper">
        <NewPageFilter
          v-model:query="filterInfo.query"
          :query-more-json="false"
          :filter-list="filterInfo.searchList"
          :filter-btn="filterInfo.searchBtn"
          :clear-type="filterInfo.clearType"
        >
        </NewPageFilter>
      </div>
      <div class="filter-wrapper">
        <NewPageFilter :filter-btn="filterInfo.btnList">
          <template v-slot:filter-remove>
            <el-button
              :disabled="tableInfo.selections.length === 0"
              @click="remove"
              >删除</el-button
            >
          </template>
        </NewPageFilter>
      </div>
      <!-- 表格 -->
      <table-container
        :refresh="tableInfo.refresh"
        :init-curpage="tableInfo.initCurpage"
        v-model:data="tableInfo.data"
        :api="tableInfo.api"
        :tab-index="true"
        :check-box="true"
        :query="filterInfo.query"
        :field-list="tableInfo.fieldList"
        :handle="tableInfo.handle"
        @handleEvent="handleEvent"
      ></table-container>
    </div>
    <Modify
      v-if="modifyInfo.visible"
      v-model:visible="modifyInfo.visible"
      :title="modifyInfo.title"
      :order-id="modifyInfo.orderId"
      @returnModify="getList"
    ></Modify>
  </div>
</template>

<script setup name="informationComparSet">
import Modify from "./modify"
import {
  getComparisonInfoSettingPage,
  deleteComparisonInfoSetting,
} from "@/api/tripartite";

const { proxy } = getCurrentInstance();
// 过滤相关配置
const filterInfo = ref({
  clearType: true,
  query: {
    sort: "create_time desc",
  },
  searchList: [
    {
      label: "对方系统",
      value: "tsSystemCode",
      event: search,
      componentType: "select-model",
      code: "client_id",
      show: true,
      hidden: true,
    },
    {
      label: "对接信息",
      value: "comparisonInfoLike",
      event: search,
      componentType: "select-model",
      code: "comparison_info",
      show: true,
      hidden: true,
    },
  ],
  searchBtn: [
    { type: "button", label: "搜索", event: search },
    { type: "button", label: "重置", event: clearSearch },
  ],
  btnList: [
    {
      type: "button",
      label: "新增",
      event: add,
      show: proxy.$permission("informationComparSet:add"),
    },
    {
      value: "remove",
      type: "slot",
      show: proxy.$permission("informationComparSet:del"),
    },
  ],
});
// 表格相关
const tableInfo = ref({
  refresh: 1,
  initCurpage: 1,
  api: undefined,
  selections: [],
  data: [],
  fieldList: [
    { label: "对方系统", value: "tsSystemCode" },
    { label: "对照信息", value: "comparisonInfoValue" },
    { label: "是否自动对照", value: "isAutoComparisonValue" },
    { label: "对照规则", value: "comparisonRuleValue" },
    { label: "创建人", value: "createUserName" },
    { label: "创建时间", value: "createTime" },
  ],
  handle: {
    fixed: "right",
    label: "操作",
    width: '50',
    btList: [
      {
        label: "删除",
        event: remove,
        popconfirmText: "删除后将改变数据,是否继续？",
        show: proxy.$permission("informationComparSet:del"),
      },
    ],
  },
});
const modifyInfo = ref({
  visible: false,
  title: "新增对接信息",
  orderId: "",
});
getList();

// 获取列表
function getList() {
  tableInfo.value.api = getComparisonInfoSettingPage;
  tableInfo.value.refresh = Math.random();
}
// 搜索
function search() {
  // 重置分页
  tableInfo.value.api = getComparisonInfoSettingPage;
  tableInfo.value.initCurpage = Math.random();
  tableInfo.value.refresh = Math.random();
}
function clearSearch() {
  filterInfo.value.clearType = !filterInfo.value.clearType;
  filterInfo.value.query = { sort: "create_time desc" };
  search();
}
// 创建
function add() {
  modifyInfo.value.visible = true;
}
function remove(row) {
  if (row && row.id) {
    let ids = [row.id];
    reRemove(ids);
  } else {
    let ids = tableInfo.value.selections.map((item) => item.id);
    proxy.$confirm("删除后将改变数据,是否继续?", "提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    }).then(() => {
      reRemove(ids);
    });
  }
}
function reRemove(ids) {
  deleteComparisonInfoSetting(ids).then((res) => {
    if (res && res.success) {
      getList();
    }
  });
}
// 触发事件
function handleEvent(event, data) {
  switch (event) {
    case "tableCheck":
      tableInfo.value.selections = data;
      break;
  }
}
</script>

<style scoped></style>
